exports.hallRoute = async function(session,msg,app,cb){
    console.log('msg--hallRoute---->',msg);
    let hallServers = app.getServersByType('hall');
    if(!hallServers && hallServers.length == 0){
        cb(new Error('can not find hall servers.'));
    }; 
    let uid = session.get('uid');
    let redis_db = app.get('redis_db');
    let serverId = await redis_db.hgetFieldAsync(uid,'serverId');
    console.log('res-serverId--->',serverId);
    if(serverId !=undefined && serverId !=null && serverId != 'connector-server-1'){
        cb(null,serverId);
    }else
    {
        let servers = await redis_db.hgetallAsync('hall');
        console.log('servers===>',servers);
        let sc = {
            serverId:-1,
            count:0
        };
        for(let server in servers){
            if(sc.serverId == -1){
                sc.serverId = server; 
                sc.count = servers[server];
            }else
            {
                if(servers[server] < sc.count){
                    sc.count = servers[server];
                    sc.serverId = server; 
                };
            }
        };
        sc.count++;
        console.log('sc======>',sc);
        let rep = await redis_db.HMSETFieldAsync('hall',sc.serverId,sc.count);
        console.log('rep---->',rep);
        await redis_db.HMSETFieldAsync(uid,'serverId',sc.serverId);
        await redis_db.HMSETFieldAsync(uid,'serverType','hall');
        cb(null,sc.serverId);
    }
}

exports.ycmjRoute = async function(session,msg,app,cb){
    console.log('session------>',session);
    console.log('msg---ycmjRoute--->',msg);
    let tid = session.get('tid');
    let uid = session.get('uid');
    console.log('msg---tid--->',tid,'uid=====>',uid);
    let key = 'ycmj:'+tid;
    let redis_db = app.get('redis_db');
    let serverId = await redis_db.hgetFieldAsync(key,'serverId');
    console.log('res-serverId--->',serverId);
    if(serverId !=undefined && serverId !=null && serverId != 'connector-server-1' && serverId != '0'){
        cb(null,serverId);
    }else{
        let servers = await redis_db.hgetallAsync('ycmj');
        console.log('servers===>',servers);
        let sc = {
            serverId:-1,
            count:0
        };
        for(let server in servers){
            if(sc.serverId == -1){
                sc.serverId = server; 
                sc.count = servers[server];
            }else
            {
                if(servers[server] < sc.count){
                    sc.count = servers[server];
                    sc.serverId = server; 
                };
            }
        };
        sc.count++;
        console.log('sc======>',sc); 
        let rep = await redis_db.HMSETFieldAsync('ycmj',sc.serverId,sc.count);
        console.log('rep---->',rep);
        await redis_db.HMSETFieldAsync(key,'serverId',sc.serverId);
        await redis_db.HMSETFieldAsync(uid,'serverId',sc.serverId);
        await redis_db.HMSETFieldAsync(uid,'serverType','ycmj');
        cb(null,sc.serverId);
    };
}